import java.util.*;
class FindSwapValues {
  public int[] findSwapValues(int[] array1, int[] array2) {

      int sum1 = 0, sum2 = 0; 
      for(int i = 0; i<array1.length; i++){
          sum1 += array1[i];
      }
      for(int i = 0; i<array2.length; i++){
          sum2 += array2[i];
      }
      if(sum1 == sum2 || (sum1 + sum2) % 2 == 1){
          return new int[0];
      }
      int diff = (sum1 + sum2)/2 - sum1;
      int[] result = new int[2];
      Arrays.sort(array2);
      for(int i = 0; i<array1.length; i++){
          int target = diff + array1[i];
          if(findIndex(array2, target) > -1){
            result[0] = array1[i];
            result[1] = target;
            return result;
          } 
      }
      return new int[0];
  }
  private int findIndex(int[] array, int target){
    int left = 0, right = array.length - 1;
    while(left <= right){
        int mid = (left + right) / 2;
        if(array[mid] == target){
            return mid;
        }else if(array[mid] < target){
            left = mid + 1;
        }else{
            right = mid - 1;
        }
    }
    return -1;
  }
}
class test { 
    public static void main(String[] args) { 
      FindSwapValues f = new FindSwapValues();
      int[] array1 = {1, 4, 3, 4, 5};
      int[] array2 = {5, 4, 3, 2, 1};
      int[] result = f.findSwapValues(array1, array2);
      for(int i = 0; i<result.length; i++){
        System.out.println(result[i]);
      }
    }
}